import time
import functools

class timeitFunc:
    def __init__(self, rangetime, func):
        self.rangetime = rangetime
        self.func = func

    def __call__(self, *args, **kwargs):
        timetime = 0
        for i in range(self.rangetime):
            timestart = time.perf_counter_ns()
            funcresult = self.func(*args, **kwargs)
            timeend = time.perf_counter_ns()
            timeused = (timeend - timestart) * pow(10, -9)
            timetime = timetime+timeused
        timetime = timetime / self.rangetime
        return (funcresult, timetime)

def timeit(rangetime):
    return functools.partial(timeitFunc, rangetime)
